//
//  NSDate+HMXDate.m
//  HMXBaisi
//
//  Created by apple on 16/7/1.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "NSDate+HMXDate.h"

@implementation NSDate (HMXDate)

-(BOOL)isThisYear
{
    //获取当前时间
    NSDate * date = [NSDate date];
    
    NSCalendar * calendar = [NSCalendar currentCalendar];
    
    NSDateComponents * currentComp = [calendar components:NSCalendarUnitYear fromDate:date];
    
    NSDateComponents * passComp = [calendar components:NSCalendarUnitYear fromDate:self];
    
    return  currentComp.year == passComp.year;
}

-(BOOL)isThisToday
{
    NSCalendar * calendar = [NSCalendar currentCalendar];
    return [calendar isDateInToday:self];
}

-(BOOL)isYestoday
{
    NSCalendar * calendar = [NSCalendar currentCalendar];
    return [calendar isDateInYesterday:self];
}

-(NSDateComponents *)betweenTime
{
    NSCalendar * calendar = [NSCalendar currentCalendar];
    
    NSDate * date = [NSDate date];
    
    return [calendar components:kCFCalendarUnitMinute|kCFCalendarUnitHour fromDate:self toDate:date options:NSCalendarWrapComponents];
}

@end
